﻿using Pipes.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;

namespace Pipes.UnitTest
{
    
    
    /// <summary>
    ///This is a test class for OracleSqlCriteriaWriterTest and is intended
    ///to contain all OracleSqlCriteriaWriterTest Unit Tests
    ///</summary>
  [TestClass()]
  public class SqlCriteriaWriterTest
  {


    private TestContext testContextInstance;

    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    ///</summary>
    public TestContext TestContext
    {
      get
      {
        return testContextInstance;
      }
      set
      {
        testContextInstance = value;
      }
    }

    #region Additional test attributes
    // 
    //You can use the following additional attributes as you write your tests:
    //
    //Use ClassInitialize to run code before running the first test in the class
    //[ClassInitialize()]
    //public static void MyClassInitialize(TestContext testContext)
    //{
    //}
    //
    //Use ClassCleanup to run code after all tests in a class have run
    //[ClassCleanup()]
    //public static void MyClassCleanup()
    //{
    //}
    //
    //Use TestInitialize to run code before running each test
    //[TestInitialize()]
    //public void MyTestInitialize()
    //{
    //}
    //
    //Use TestCleanup to run code after each test has run
    //[TestCleanup()]
    //public void MyTestCleanup()
    //{
    //}
    //
    #endregion


    public void PerformTest(Action<ICriteriaWriter> testCase, string expected)
    {
      using (var writer = new System.IO.StringWriter())
      {
        using (var sql = new OracleSqlCriteriaWriter(writer))
        {
          testCase.Invoke(sql);
        }
        Assert.AreEqual(expected, writer.ToString());
      }
    }

    [TestMethod()]
    public void OracleSqlCriteriaWriterConstructorTest()
    {
      PerformTest((sql) => {
        sql.Logical(LogicalOperator.And);
        sql.Identifier("test_case");
        sql.Comparison(ComparisonType.Contains);
        sql.StringValue("value");
        sql.Identifier("created_on");
        sql.Comparison(ComparisonType.LessThan);
        sql.DateValue(new DateTime(2013, 5, 1));
        sql.LogicalEnd();
      }, "[test_case] LIKE '%value%' AND [created_on] < to_date('2013-05-01 00:00:00', 'YYYY-MM-DD HH:MI:SS'))");
    }
  }
}
